/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sbmart.util;

import java.net.InetAddress;
import java.sql.Connection;
import java.sql.SQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author albert
 *
 */
public class Ping {
    
    public static final Logger LOG = LoggerFactory.getLogger("Connection");

    public static boolean isReachable(String ipaddress) {
        try {
//            InetAddress address = InetAddress.getByName(ipaddress);
//            boolean reachable = address.isReachable(8000);
            return InetAddress.getByName(ipaddress).isReachable(8000);
        } catch (Exception e) {
            LOG.error("[ERROR] PING exception:", e);
        }
        return false;
    }
    
    public void isOpen(Connection conn) throws SQLException {
        if (conn.isClosed()) {
            throw new SQLException("[ERROR]: Connection was Closed.");
        }
    }
}
